import { cooperationBehavior } from "../../../../behaviors/cooperation";
import api from "../../../../common/api";
// pages/im/com/option-item/option-item.js
Component({
  behaviors: [cooperationBehavior],
  /**
   * 组件的属性列表
   */
  properties: {
    cooperationId: {
      type: String,
      default: "",
    },
    userID: String,
  },

  options: {
    styleIsolation: "apply-shared",
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    status: true, //是否已复制过该房源
    cooperationDown: false, //是否已取消合作
    isMine: true, // 该房源是否是我的
  },

  lifetimes: {
    attached: function () {
      api.queryCopyHouseStatus({ 
        cooperationId: this.data.cooperationId,
        houseInviteId: getApp().globalData.sessionUser.id
      }, ({ data }) => {
        this.setData({
          status: !!data.content.copyHouseStatus
        })
      });

      this.getInfoByCooperationId(this.data.cooperationId).then(({ jjrVO }) => {
        if (jjrVO && jjrVO.wechatUnionid !== this.data.userID) {
          this.setData({ isMine: false })
        }
      })
    },

    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleComplain() {
      this.triggerEvent("oncomplain", { cooperationId: this.data.cooperationId });
    },
    handleCopyHouse() {
      this.triggerEvent("oncopyhouse", { cooperationId: this.data.cooperationId });
    },
  },
});
